package com.example.leetdemo.finash;

import java.util.Arrays;

public class Solution821 {

    public static int[] shortestToChar(String s, char c) {
        int[] res = new int[s.length()];
        String[] sub = s.split(String.valueOf(c));
        int count = 0;
        for (int i = 0; i < sub.length; i++) {
            for (int j = 0; j < sub[i].length(); j++) {
                if (i == 0 && s.charAt(0) != c) {
                    res[count] = sub[i].length() - j;
                } else if (i == sub.length - 1 && s.charAt(s.length() - 1) != c) {
                    res[count] = j + 1;
                } else {
                    res[count] = Math.min(j + 1, sub[i].length() - j);
                }
                count++;
            }
            if (count < res.length) {
                res[count] = 0;
                count++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
//        String[] sub = "oveleetcod".split("e");
//        for (int i = 0; i < sub.length; i++ ) {
//            System.err.println(sub[i]);
//        }
        System.err.println(Arrays.toString(shortestToChar("loveleetcode", 'e')));
        System.err.println("[3,2,1,0,1,0,0,1,2,2,1,0]");
    }

}
